package com.chinasofti.info_manager.service;


import com.chinasofti.info_manager.dao.TeacherDao;
import com.chinasofti.info_manager.domain.Teacher;

public class TeacherService {

    TeacherDao teacherDao = new TeacherDao();

    public static Teacher[] findAllTeacher() {
        Teacher[] allTeacherts = TeacherDao.findAllTeacher();
        boolean flag = false;//做一个开关；allStudents有值怎返回；allStudents没有值返回null
        for (int i=0;i<allTeacherts.length;i++){
            Teacher stu = allTeacherts[i];
            if(stu != null){
                flag = true;
                break;
            }
        }
        if(flag){
            return allTeacherts;
        }else {
            return null;
        }

    }

    //判断学号是否存在
    public boolean isExists(String id) { //返回值weitrue代表 id不存在
        boolean exists = false;
        //判断数组中是否有这个id
        int index = teacherDao.getIndex(id);
        if (index == -1) {
            exists = true; //不存在
        }
        return exists;
    }

    public boolean addTeacher(Teacher tea) {
        return teacherDao.addTeacher(tea);
    }


    public void deleteStudentById(String delId) {
        teacherDao.deleteTeacherById(delId);
    }
    public void updateTeacher(String updateId, Teacher newTea) {
        teacherDao.updateTeacher(updateId,newTea);
    }
}